package com.jvyou.driver.controller;

import com.jvyou.driver.domain.modal.Result;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 橘柚
 * @version 1.0-SNAPSHOT
 * @Date 2024/8/11 20:11
 * @Description
 */
@RestController
@RequestMapping("test")
public class TestController {

    @GetMapping("/success")
    public Result<String> success(@RequestParam(value = "message", defaultValue = "Operation successful") String message) {
        return Result.okResult(message);
    }

    @GetMapping("/error")
    public Result<Void> error(@RequestParam(value = "code", defaultValue = "500") int code,
                              @RequestParam(value = "message", defaultValue = "Internal Server Error") String message) {
        return Result.errorResult(code, message);
    }

    @GetMapping("/data")
    public Result<Map<String, Object>> data() {
        Map<String, Object> data = Map.of("name", "jvyou", "age", 18);
        return Result.okResult(data);
    }

    @PostMapping("/post")
    public Result<Map<String, Object>> post(@RequestBody Map<String, Object> data) {
        return Result.okResult(data);
    }

    @DeleteMapping("/delete")
    public Result<Integer> delete(int id) {
        return Result.okResult(id);
    }
}
